public class Text8 {
    public String addBinary(String a, String b) {
        StringBuffer Str = new StringBuffer();

        int n = Math.max(a.length(),b.length());
        int carry = 0;

        // for(int i = n - 1; i > 0; --i){
        //     carry += i < a.length()?(a.charAt(i) - '0') : 0;
        //     carry += i < b.length()?(b.charAt(i) - '0') : 0;
        //     Str.append((char)carry % 2 + '0');
        //     carry /= 2;
        // }

        for (int i = 0; i < n; ++i) {
            carry += i < a.length() ? (a.charAt(a.length() - 1 - i) - '0') : 0;
            carry += i < b.length() ? (b.charAt(b.length() - 1 - i) - '0') : 0;
            Str.append((char) (carry % 2 + '0'));
            carry /= 2;
        }

        if(carry > 0){
            Str.append('1');
        }

        Str.reverse();

        return Str.toString();
    }
}
